<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="12">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>非遗数据统计</span>
            </div>
          </template>
          <div class="chart-wrapper">
            <div ref="heritageChart" style="height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>商品销售统计</span>
            </div>
          </template>
          <div class="chart-wrapper">
            <div ref="salesChart" style="height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row :gutter="20" style="margin-top: 20px;">
      <el-col :span="12">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>论坛活跃度</span>
            </div>
          </template>
          <div class="chart-wrapper">
            <div ref="forumChart" style="height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card class="box-card">
          <template #header>
            <div class="card-header">
              <span>用户增长趋势</span>
            </div>
          </template>
          <div class="chart-wrapper">
            <div ref="userChart" style="height: 300px;"></div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'

const heritageChart = ref(null)
const salesChart = ref(null)
const forumChart = ref(null)
const userChart = ref(null)

function initHeritageChart() {
  const chart = echarts.init(heritageChart.value)
  chart.setOption({
    title: {
      text: '非遗分类统计'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      orient: 'vertical',
      left: 'left'
    },
    series: [
      {
        type: 'pie',
        radius: '50%',
        data: [
          { value: 35, name: '传统技艺' },
          { value: 25, name: '传统美术' },
          { value: 20, name: '传统音乐' },
          { value: 15, name: '传统舞蹈' },
          { value: 5, name: '其他' }
        ],
        emphasis: {
          itemStyle: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    ]
  })
}

function initSalesChart() {
  const chart = echarts.init(salesChart.value)
  chart.setOption({
    title: {
      text: '近7天销售趋势'
    },
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line',
        smooth: true
      }
    ]
  })
}

function initForumChart() {
  const chart = echarts.init(forumChart.value)
  chart.setOption({
    title: {
      text: '论坛活跃度分析'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['发帖数', '评论数']
    },
    xAxis: {
      type: 'category',
      data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name: '发帖数',
        type: 'bar',
        data: [120, 132, 101, 134, 90, 230, 210]
      },
      {
        name: '评论数',
        type: 'bar',
        data: [220, 182, 191, 234, 290, 330, 310]
      }
    ]
  })
}

function initUserChart() {
  const chart = echarts.init(userChart.value)
  chart.setOption({
    title: {
      text: '用户增长趋势'
    },
    tooltip: {
      trigger: 'axis'
    },
    xAxis: {
      type: 'category',
      data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月']
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        data: [150, 230, 224, 218, 135, 147, 260],
        type: 'line',
        smooth: true,
        areaStyle: {}
      }
    ]
  })
}

onMounted(() => {
  initHeritageChart()
  initSalesChart()
  initForumChart()
  initUserChart()
})
</script>

<style scoped>
.chart-wrapper {
  background: #fff;
  padding: 16px 16px;
  margin-bottom: 20px;
}
</style> 